<template>
  <div>
    <h2>物流相关信息</h2>
    <div class="logistics-info-header">
      <div class="logistics-info-header-left">
        <div
          :class="
            currentColor === 0
              ? 'black'
              : currentColor === 1
              ? 'red'
              : currentColor === 2
              ? 'blue'
              : currentColor === 3
              ? 'grey'
              : ''
          "
        >
          {{ state }}
        </div>
        <div class="logistics-company">{{ list.logisticsCompany }}</div>
        <div class="logistics-no">{{ list.logisticsNo }}</div>
      </div>
    </div>
    <ul class="logistics-info-list" v-show="flag">
      <li v-for="item in list.logisticsInfo" :key="item.time">
        <div class="logistics-info-list-time">{{ item.time }}</div>
        <div class="logistics-info-list-content">
          {{ item.content }}
        </div>
      </li>
    </ul>
    <button @click="view" v-if="!flag">查看物流详情</button>
    <button @click="hide" v-else>收起</button>
  </div>
</template>
<script>
export default {
  name: 'LogisticsComponents',
  props: {
    list: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      flag: false,
    }
  },
  methods: {
    view() {
      if (
        this.list.role === 'admin' ||
        this.list.role === 'zhangsan' ||
        this.list.role === 'lisi'
      ) {
        this.flag = true
      } else {
        alert('您没有访问权限！')
      }
    },
    hide() {
      this.flag = false
    },
  },
  computed: {
    state() {
      switch (this.list.logisticsStatus) {
        case 0:
          return '未发货'
        case 1:
          return '已发货'
        case 2:
          return '已签收'
        case 3:
          return '未签收'
        default:
          return '无'
      }
    },
    currentStatus() {
      return this.list.logisticsInfo[this.list.logisticsInfo.length - 1]
    },
    currentColor() {
      return this.list.logisticsStatus
    },
  },
}
</script>
<style scoped>
img {
  width: 250px;
}
.logistics-info {
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0px 0px 10px #eee;
  padding: 10px;
  font-size: 14px;
}

.logistics-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.logistics-info-header-left {
  display: flex;
  align-items: center;
}

.black {
  font-weight: bold;
  font-size: 16px;
  color: #000000;
}

.red {
  font-weight: bold;
  font-size: 16px;
  color: #ff0015;
}

.blue {
  font-weight: bold;
  font-size: 16px;
  color: #007bff;
}

.grey {
  font-weight: bold;
  font-size: 16px;
  color: #c5cfd6bc;
}

.logistics-company,
.logistics-no {
  margin-left: 10px;
  font-size: 14px;
  color: #333;
}

.logistics-info-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 230px;
  overflow-y: auto;
}

.logistics-info-list li {
  display: flex;
  margin-bottom: 10px;
}

.logistics-info-list-time {
  font-size: 12px;
  color: #999;
  width: 80px;
  text-align: right;
  margin-right: 10px;
}

.logistics-info-list-content {
  font-size: 14px;
  color: #333;
}
</style>
